<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <title>JS Bin</title>
</head>

<body>
    <!-- 案例1 -->
    <script>
        var a = 1;

        function a() {};
        a = 200;
        var b = undefined;
        console.log(a);
        if (true) {
            a = 2;
            a = 100;
            console.log(a);

            function a() {}; // 可以替换为 a = function() {}看看效果
            console.log(a);
            b = undefined;

            function b() {}; // 可以替换为 b = function() {}看看效果
            console.log(b);
            b = 4;
            a = 5;
            console.log(a);
            a = 21;
            console.log(a);
        }
        console.log(a);
        console.log(b);
    </script>
    <!-- 案例2 -->
    <!-- <script>
        var a = 1;
        console.log(a);
        if (true) {
            a = 2;
            a = 100;
            console.log(a);

            function a() {};
            // a = function () {}
            a = 5;
            console.log(a);
            a = 21;
            console.log(a);
        }
        console.log(a);
    </script> -->
    <!-- 案例3 -->
    <!-- <script>
    var a = 1;
    console.log(a);
    if(true) {
      function a() {};
      a = 5;
      console.log(window.a);
      a = 21;
      console.log(window.a);
    }
    console.log(a);
  </script> -->
</body>

</html>